
public class Play_piano {
	public int countBeat=1;
	public int copy=100;
	public int canon=0;
	public int[] lengthArray = new int[] {0,16,20,0,21,0,0,0,0,18,0,0,0,32,7,16,16};
	public int wait=0;
	public void melody1() {
    	Main.score.melody1(72,16,16,2,1);
	}
	public void melody2() {
		Main.score.melody2(72,20,20,2,1);
	}

	public void melody4() {
		Main.score.melody4(71,21,21,2,1);
	}

	public void melody9() {
		Main.score.melody9(60,18,18,2,1);
	}
	public void melody11() {
		Main.score.melody11(72,16,16,2,1);
	}
	public void melody13() {
		Main.score.melody13(67,16,16,2,1);
//		Main.score.melody13(67,32,32,2,1);
	}
	public void melody14() {
    	Main.score.melody14(48,7,7,0,0);
	}
	public void melody15() {
		Main.score.melody15(48,16,16,0,0);
	}
	public void melody16() {
    	Main.score.melody16(72,16,16,2,1);
	}
	public void melody(int i){
		
		
		



//		wait # of cycles
		int randWait = (int) (Math.random()*100);
		if (randWait>wait)
		{
	//		canonize
			if (Math.random()*100<canon)
			{
				int wait=0;
				int canonPoint = (int) (Math.random()*100);
				if (canonPoint<33)
				{
					wait=3;
				}
				else if (canonPoint<66)
				{
					wait=5;
				}
				else 
				{
					wait=7;
				}
				Main.score.waitMil(Main.quarter*wait);			
			}
			
			switch(i)
			{
			case(1):
	    		Main.quarter=(int) (countBeat/8.5);
				Main.score.playing1=1;
	    		Main.score.waitMil(Main.quarter*6.-500.);
	        	Main.score.clearScheduler(1);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing0=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
	        	Main.score.noteOut(95,0,3);
				if (Math.random()*100<copy)
				{
					melody1();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody4();
					}
					else 
					{
						melody16();
					}
				}
				break;
			case(2):
	    		Main.quarter=(int) (Main.play.countBeat/8.5);
    			Main.score.playing1=2;
				Main.score.waitMil(Main.quarter*7.);
				Main.score.clearScheduler(1);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing0=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
				Main.score.waitMil(Main.quarter*2.-500.);

				if (Math.random()*100<copy)
				{
					melody2();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody4();
					}
					else 
					{
						melody1();
					}
				}
				break;
			case(4):
	    		Main.quarter=(int) (Main.play.countBeat/10.5);
    			Main.score.playing1=4;
				Main.score.waitMil(Main.quarter*7.5);
	        	Main.score.clearScheduler(1);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing0=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
	    		Main.score.waitMil(Main.quarter*2.-500.);
				if (Math.random()*100<copy)
				{
					melody4();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody1();
					}
					else 
					{
						melody14();
					}
				}
				break;
			case(9):
    			Main.score.playing1=9;
				Main.score.waitMil(Main.quarter*5.95);
				Main.score.clearScheduler(1);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing0=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
				Main.score.waitMil(Main.quarter*2.5-500.);
				if (Math.random()*100<copy)
				{
					melody9();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody15();
					}
					else 
					{
						melody16();
					}
				}
				break;
			case(11):
    			Main.score.playing1=11;
				Main.score.waitMil(Main.quarter*6.);
	        	Main.score.clearScheduler(1);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing0=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
	    		Main.score.waitMil(Main.quarter*2-500.);

				if (Math.random()*100<copy)
				{
					melody11();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody4();
					}
					else 
					{
						melody9();
					}
				}
				break;
			case(13):
    			Main.score.playing1=13;
				Main.score.waitMil(Main.quarter*8.8);
	        	Main.score.clearScheduler(1);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing0=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
				Main.score.waitMil(Main.quarter);
				Main.score.noteOut(72,0,2);	
	    		Main.score.waitMil(Main.quarter*2-500.);
				if (Math.random()*100<copy)
				{
					melody13();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody11();
					}
					else 
					{
						melody15();
					}
				}
				break;
			case(14):
	        	Main.score.clearScheduler(0);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing1=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
	        	Main.score.noteOut(48,0,0);
				Main.score.playing0=14;
	    		Main.score.waitMil(Main.quarter*1.5-500.);
	        	Main.score.noteOut(55,0,1);

				if (Math.random()*100<copy)
				{
					melody14();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody2();
					}
					else 
					{
						melody9();
					}
				}
				break;
			case(15):
    			Main.score.playing0=15;
				Main.score.waitMil(Main.quarter*6.);
    			Main.score.clearScheduler(0);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing1=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
	    		Main.score.waitMil(Main.quarter*2.-500.);

				if (Math.random()*100<copy)
				{
					melody15();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody13();
					}
					else 
					{
						melody11();
					}
				}
				break;
			case(16):
				Main.score.playing1=16;
	    		Main.score.waitMil(Main.quarter*8.95);
	        	Main.score.clearScheduler(1);
	        	if (Main.section==1)
	        	{
	        		Main.score.playing0=99;
		        	Main.score.clearScheduler(1);
		        	Main.score.clearScheduler(0);	        		
	        	}
	    		Main.score.waitMil(Main.quarter*1.);
	        	Main.score.noteOut(72,0,2);		        	
	    		Main.score.waitMil(Main.quarter*2.-500.);


				if (Math.random()*100<copy)
				{
					melody16();
				}
				else
				{
					if (Math.random()<.5)
					{
						melody13();
					}
					else 
					{
						melody14();
					}
				}
				break;
			}
		}
	}
}
